package com.sunday.haowushop.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.sunday.common.base.BaseActivity;
import com.sunday.common.widgets.recyclerView.HorizontalDividerItemDecoration;
import com.sunday.haowushop.R;
import com.sunday.haowushop.adapter.CommonAdapter;
import com.sunday.haowushop.adapter.ViewHolder;
import com.sunday.haowushop.entity.HelpList;
import com.sunday.haowushop.ui.WebViewActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘涛 on 2017/7/6.
 */

public class HelpListActivity extends BaseActivity {

    @Bind(R.id.title_view)
    TextView titleView;
    @Bind(R.id.recycler_view)
    RecyclerView recyclerView;

    private List<HelpList> dataSet = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_list);
        ButterKnife.bind(this);
        String title = getIntent().getStringExtra("title");
        dataSet = getIntent().getParcelableArrayListExtra("helpList");
        titleView.setText(title);
        initRecyclerView();
    }


    private void initRecyclerView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(mContext).drawable(R.drawable.divider).build());
        recyclerView.setAdapter(new CommonAdapter<HelpList>(mContext, R.layout.help_list_item,dataSet) {

            @Override
            public void convert(ViewHolder holder, final HelpList helpList) {
                ((TextView)holder.getView(R.id.content)).setText(helpList.getName());
                holder.setOnClickListener(R.id.content, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String url = String.format("http://admin.zj-yunti.com/DataController/helpInfo?id=%d", helpList.getId());
                        String title = helpList.getName();
                        intent = new Intent(mContext, WebViewActivity.class);
                        intent.putExtra("title", title);
                        intent.putExtra("url", url);
                        startActivity(intent);
                    }
                });
            }
        });
    }


}
